var express = require('express');
var bodyParser = require('body-parser')
var exec = require('child_process').exec;

var app = express();

app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));
app.use('/', express.static(__dirname + '/template'));

app.post('/get', function (req, res) {
	con = req.body.con;
	con = con.replace(/[\n]/g,"@");
	var resultjson = [];
    exec('python continue.py ' + con, function(err, stdout, stderr) {
    	// console.log(stdout);
    	stdout = stdout.replace(/[']/g,"\"");
    	stdout1 = JSON.parse(stdout);
    	// console.log(typeof(stdout1));
    	res.json(stdout1);
    });
    // console.log(resultjson);
    // resultjson是返回数据，现在先使用假数据
    // var resultjson = [{id: 1, rank: 0}, {id: 3, rank: 1}, {id: 6, rank: 0}, {id: 7, rank: 0},];
    // console.log(typeof(resultjson))
    // res.json(resultjson);
});

app.listen(3000);